package com.bybops.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

public class TimeUtils {

    public static final  SimpleDateFormat dateFormat_1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static final  SimpleDateFormat dateFormat_2 = new SimpleDateFormat("MM-dd");
    public static final  SimpleDateFormat dateFormat_3 = new SimpleDateFormat("yyyy-MM-dd");
    public static final  SimpleDateFormat dateFormat_4 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    public static final  SimpleDateFormat dateFormat_5 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static GregorianCalendar gregorianCalendar = new GregorianCalendar();

    public static long stringToLong(SimpleDateFormat format , String stringDate){
        try {
            Date d = format.parse(stringDate);
            return d.getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return 0;
    }

    public static int amOrPm(long time){
        int n = 0;
        gregorianCalendar.setTimeInMillis(time);
        if (gregorianCalendar.get(GregorianCalendar.AM_PM) == 0){
            //上午
            n = 0;
        }else if (gregorianCalendar.get(GregorianCalendar.AM_PM) == 1){
            //下午
            n = 1;
        }
        return n;
    }

    public static String commLongToString(SimpleDateFormat format, long time) {
        return format.format(new Date(time));
    }
}
